<?php
namespace app\adminhtml;

use app\BaseController as Base;
use think\facade\Session;

/**
 * 应用控制器基础类
 */
abstract class BaseController extends Base
{
    /**
     * 应用名称
     */
    protected $appname;

    /**
     * 控制器名称
     */
    protected $controller;

    /**
     * 操作名称
     */
    protected $action;

    /**
     * 帐号ID
     */
    protected $admin_auth_id;

    /**
     * 初始化
     *
     * @return void
     */
    protected function initialize()
    {
        parent::initialize();

        $this->appname    = "adminhtml";
        $this->controller = strtolower($this->request->controller());
        $this->action     = strtolower($this->request->action());

        // 除index控制器外，剩余所有页面都需要验证权限
        if ($this->controller != "index") {
            $admin_auth_id = Session::get("admin_auth_id");
            if (empty($admin_auth_id)) {
                // die(json_encode(errorful("权限不足base"), JSON_UNESCAPED_UNICODE));
                $html  = '<html><head><meta charset="utf-8" /><title>授权过期</title></head><body>';
                $html  = '<p>授权过期，请重新登录！</p>';
                $html .= '<script>alert("授权过期，请重新登录！");window.location.href="/adminhtml/index/index.html";</script>';
                $html .= '</body></html>';
                die($html);
            }

            $this->admin_auth_id = $admin_auth_id;
            $this->assign("admin_auth_id", $admin_auth_id);
        }
    }

    
}
